﻿using System.ServiceModel;
using Ledict.ConditionExtract.BLL;
using Ledict.ConditionExtract.Common;
//using Ledict.ConditionExtract.TestApp;
using Ledict.Core.Data;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Common;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Ledict.Utility.Msg;

namespace Ledict.ConditionExtract
{
    public partial class TestForm : Form
    {
        Database oBase = DatabaseFactory.CreateDatabase("JudgeDoc");
        string sOrder = string.Empty;


        //CallBackClient callBack;

        public TestForm()
        {
            InitializeComponent();
            //callBack = new CallBackClient();
            //callBack.ValueCallback += (sender, i) =>
            //{
            //    label1.Text = i.ToString();
            //};
        }

        
        private void button1_Click(object sender, EventArgs e)
        {
            //            string sql = @"select  CC_ID as id,CC_Name as name, CC_NodeType,2 as ES_IsMakeUp, 0 as TableName  from dbo.SYS_CaseCause
            //	                    where CC_ParentID='2449' order by CC_SerialNumb";
            //            test(getDataTableSql(sql), "");
            //string s1 = LdFormat.OrderEdit("000600010001000100010002", 3, 1);
            //int num2 = LdFormat.OrderGet("000600010001000100010002", 1);
            //AnalysisXML xml = new AnalysisXML();
            //xml.AnalyArgumentTypeXml();
        }

        private void test(DataTable dt, string pOrder)
        {
            if (null != dt)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    sOrder = string.Format("{0}{1}", pOrder, LdFormat.OrderFormat(i + 1));
                    DataRow dr = dt.Rows[i];
                    execSql(string.Format("update SYS_CaseCause set CC_AllPidSerialNumb = '{0}' where CC_ID = '{1}'",
                        sOrder, dr["id"]));
                    string sql = string.Format(@"select  CC_ID as id,CC_Name as name, CC_NodeType,2 as ES_IsMakeUp, 0 as TableName  from dbo.SYS_CaseCause
	                    where CC_ParentID='{0}' order by CC_SerialNumb", dr["id"]);
                    test(getDataTableSql(sql), sOrder);
                }
            }
        }

        private DataTable getDataTableSql(string sql)
        {
            DbCommand oCmd = oBase.GetSqlStringCommand(sql);
            DataSet ds = oBase.ExecuteDataSet(oCmd);
            if (0 < ds.Tables.Count && 0 < ds.Tables[0].Rows.Count)
            {
                return ds.Tables[0];
            }
            return null;
        }

        private void execSql(string sql)
        {
            DbCommand oCmd = oBase.GetSqlStringCommand(sql);
            oBase.ExecuteNonQuery(oCmd);
        }

        //InstanceContext instanceContext = new InstanceContext(program);


        private void button2_Click(object sender, EventArgs e)
        {
            ////WCF 回调测试

            //TestApp.ITest test = new TestClient(new InstanceContext(callBack));
            //test.CallServerOperation();

        }
    }

    //public class CallBackClient : TestApp.ITestCallback
    //{
    //    /// <summary>  
    //    /// 回调引发该事件  
    //    /// </summary>  
    //    public event EventHandler<int> ValueCallback;  

    //    public void CallClient(int value)
    //    {
    //        if (ValueCallback != null)
    //        {
    //            ValueCallback(this, value);
    //        }
            
    //    }
    //}

}


